package cn.ffcs.uec.payroll.action;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Components;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zkplus.databind.BindingListModelList;
import org.zkoss.zul.ListModelList;

import cn.ffcs.raptornuke.plugin.common.zk.ctrl.BasePortletComposer;
import cn.ffcs.uec.payroll.action.bean.UecPayRollListMainBean;
import cn.ffcs.uec.payroll.manager.UecPayRollManager;
import cn.ffcs.uec.payroll.model.UecPayRoll;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.NumericUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Controller
@Scope("prototype")
public class UecPayRollListMainComposer extends BasePortletComposer {

	private static final long serialVersionUID = -2497274555244653652L;

	private UecPayRollListMainBean bean = new UecPayRollListMainBean();

	private UecPayRoll qryUecPayRoll;
	
	private UecPayRoll uecPayRoll;
	
	private UecPayRollManager uecPayRollManager = (UecPayRollManager) ApplicationContextUtil
			.getBean("uecPayRollManager");

	@Override
	public void doAfterCompose(Component comp) throws Exception {
		super.doAfterCompose(comp);
		Components.wireVariables(comp, bean);
	}
	/**
	 * 初始化
	 */
	public void onCreate$uecPayRollListMainWin() {
		this.bindBean();
		this.onQueryUecPayRoll();
	}
	/**
	 * 选择查询记录
	 * 
	 * @throws Exception
	 */
	public void onSelectRequest() throws Exception {
		if (this.bean.getUecPayRollListbox().getSelectedCount() > 0) {
			uecPayRoll = (UecPayRoll) bean.getUecPayRollListbox()
					.getSelectedItem().getValue();
			Events.postEvent("onOK", this.self, uecPayRoll);
			this.onCancel();
		}
	}
	/**
	 * bindBean
	 */
	public void bindBean() {
		//opType = (String) arg.get("opType");
		//if ("outStaffList".equals(opType)) {
			this.bean.getUecPayRollListMainWin().setTitle("员工选择列表");
			qryUecPayRoll = (UecPayRoll) arg.get("qryUecPayRoll");
			/*if (null != qryUecOutStaffInfo) {

			}*/
		//}
	}


	/**
	 * 取消
	 */
	public void onCancel() {
		this.bean.getUecPayRollListMainWin().onClose();
	}
	/**
	 * 查询
	 */
	public void onQueryUecPayRoll() {
		if (null != qryUecPayRoll) {
			int activePage = bean.getUecPayRollListboxPaging().getActivePage();
			int pageSize = bean.getUecPayRollListboxPaging().getPageSize();
			PageInfo pageInfo = uecPayRollManager
					.queryPageInfoByUecPayRoll(qryUecPayRoll, activePage + 1,
							pageSize);
			ListModelList dataList = new BindingListModelList(
					pageInfo.getDataList(), true);
			bean.getUecPayRollListbox().setModel(dataList);
			bean.getUecPayRollListboxPaging().setTotalSize(
					NumericUtil.nullToZero(pageInfo.getTotalCount()));
		}

	}
	/**
	 * 翻页
	 */
	public void onUecPayRollListboxPaging() {
		this.onQueryUecPayRoll();
	}

}
